<template>
  <div class="leftchild1">
    <header>
      <li>工作台</li>
      <h1>您好,{{ `欢迎` + state.title }}</h1>
      <li>您的角色：{{ state.name }}</li>
    </header>
    <main>
      <div class="charts">
        <li>面板导航</li>
        <ChartsView />
      </div>
      <div class="top-router">
        <li>快速导航</li>
        <div class="router">
          <p><router-link to="/allessay">文章管理</router-link></p>
          <p><router-link to="/commenton">评论管理</router-link></p>
          <p><router-link to="/document">文件管理</router-link></p>
          <p><router-link to="/user">用户管理</router-link></p>
          <p><router-link to="/visit">访问管理</router-link></p>
          <p><router-link to="/system">系统设置</router-link></p>
        </div>
      </div>
      <div class="essay">
        <li>
          <span>最新文章</span>
          <span><router-link to="/allessay">全部文章</router-link></span>
        </li>
        <div class="essay-main">
          <div v-for="(item, index) in state.list" :key="index">
            <p>文章封面</p>
            <p>{{ item.title }}</p>
          </div>
        </div>
      </div>
      <div class="footer">
        <li>
          <span>最新文章</span>
          <span><router-link to="/commenton">全部评论</router-link></span>
        </li>
        <div class="f-main">
          <div v-for="(item, index) in state.data" :key="index">
            <p>
              {{ item.name }}&nbsp;在
              <span>文章</span>
              评论
              <span>
                <a-popover title="评论详情-原始内容">
                  <template #content>
                    <p>{{ item.content }}</p>
                  </template>
                  <span>查看内容</span>
                </a-popover>
              </span>
            </p>
            <p>
              <span>通过</span>
              <span>拒绝</span>
              <span>
                <span @click="showModal">回复</span>
                <a-modal
                  v-model:visible="visible"
                  title="回复评论"
                  @ok="handleOk"
                  cancelText="取消"
                  okText="回复"
                >
                  <a-textarea
                    v-model:value="value"
                    placeholder="支持 MarkDown"
                    :rows="4"
                  />
                </a-modal>
              </span>
              <span>
                <a-popconfirm
                  title="确认删除这个评论？"
                  ok-text="确认"
                  cancel-text="取消"
                  @confirm="confirm"
                  @cancel="cancel"
                >
                  <a href="#">
                    <span>删除</span>
                  </a>
                </a-popconfirm>
              </span>
            </p>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, onMounted, ref } from 'vue'
import ChartsView from '@/components/ChartsView.vue'
import { message } from 'ant-design-vue'
import axios from 'axios'
export default defineComponent({
  components: {
    ChartsView
  },
  setup() {
    let state: any = reactive({
      title: localStorage.getItem('username'),
      name: localStorage.getItem('role'),
      list: [
        {
          title: ''
        }
      ],
      data: [
        {
          name: '',
          content: ''
        }
      ]
    })
    onMounted(() => {
      axios.get('https://creationapi.shbwyz.com/api/article').then((res) => {
        state.list = res.data.data[0]
      })
      axios.get('https://creationapi.shbwyz.com/api/comment').then((res) => {
        state.data = res.data.data[0]
      })
    })
    const confirm = (e: MouseEvent) => {
      console.log(e)
      message.warning('访客无权进行该操作')
    }

    const cancel = (e: MouseEvent) => {
      console.log(e)
    }
    const visible = ref<boolean>(false)

    const showModal = () => {
      visible.value = true
    }

    const handleOk = (e: MouseEvent) => {
      console.log(e)
      visible.value = false
    }
    const value = ref<string>('')
    return {
      state,
      confirm,
      cancel,
      visible,
      showModal,
      handleOk,
      value
    }
  }
})
</script>

<style lang="scss">
.leftchild1 {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  header {
    height: 23%;
    padding-left: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    background: #fff;
    border-top: 1px solid #eae2e2;
    li {
      font-size: 15px;

      &:nth-child(1) {
        color: #777;
      }

      &:nth-child(3) {
        margin-bottom: 10px;
      }
    }

    h1 {
      font-size: 35px;
      font-weight: bold;
    }
  }

  main {
    flex-grow: 1;
    overflow-y: scroll;

    li {
      height: 50px;
      border-bottom: 1px solid #eae2e2;
      display: flex;
      align-items: center;
      padding-left: 10px;
    }

    .charts {
      width: 97%;
      height: 350px;
      background: #fff;
      margin: 3% auto;
    }

    .top-router {
      width: 97%;
      height: 150px;
      background: #fff;
      margin: 3% auto;

      .router {
        height: 90px;
        display: flex;
        align-items: center;
        justify-content: space-around;

        p {
          cursor: pointer;
        }
      }
    }

    .essay {
      width: 97%;
      height: 350px;
      background: #fff;
      margin: 3% auto;

      li {
        display: flex;
        justify-content: space-between;
        margin: 0 10px;
        cursor: pointer;
      }

      .essay-main {
        display: flex;
        flex-wrap: wrap;

        div {
          width: 32%;
          height: 140px;
          margin: 5px;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: space-around;
          border: solid 1px #eae2e2;

          &:hover {
            box-shadow: 4px 4px 4px #ededed;
          }
        }
      }
    }

    .footer {
      width: 97%;
      height: 350px;
      background: #fff;
      margin: 3% auto;
      overflow: hidden;

      li {
        display: flex;
        justify-content: space-between;
        margin: 0 10px;
        cursor: pointer;
      }

      .f-main {
        div {
          display: flex;
          justify-content: space-between;
          height: 50px;
          align-items: center;
          border-bottom: 1px solid #eae2e2;

          p {
            margin: 0 20px;

            span {
              margin: 0 5px;
              cursor: pointer;
              color: #0078d7;
            }
          }
        }
      }
    }
  }
}

.ant-modal-mask {
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.1);
}
</style>
